package com.zjdiepu.www.base.lang;

import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;
/**
 * 顺序加载properties<br/>
 * Properties  key/value 都是直接存在 Hashtable 中的，而 Hashtable 是不保证进出顺序的。<br/>
 * @author xiongxiaotun@126.com
 * @time 2017年4月1日 下午11:02:23
 * @since 1.0.0
 * @update
 */
public class SortedProperties extends Properties {
	private static final long serialVersionUID = -4627607243846121965L;
    
    private final LinkedHashSet<Object> keys = new LinkedHashSet<Object>();

    public Enumeration<Object> keys() {
        return Collections.<Object> enumeration(keys);
    }

    public Object put(Object key, Object value) {
        keys.add(key);
        return super.put(key, value);
    }

    public Set<Object> keySet() {
        return keys;
    }

    public Set<String> stringPropertyNames() {
        Set<String> set = new LinkedHashSet<String>();

        for (Object key : this.keys) {
            set.add((String) key);
        }

        return set;
    }
}
